﻿#include "stdafx.h"

#include "svgbottomtoolbar.h"
#include "svgpalette.h"

#include <QComboBox>
#include <QHBoxLayout>
#include <QSpacerItem>

constexpr auto SCALE_COMBOBOX_ITEMS = { "10", "20", "50", "100", "150", "200" , "300", "500", "800", "1000" };

SvgBottomToolBar::SvgBottomToolBar(QWidget* parent)
	: QWidget(parent)
	, palette(new SvgPalette(this))
	, m_scaleComboBox(new QComboBox(this))
{
	setFixedHeight(40);
	const auto layout = new QHBoxLayout(this);
	layout->setContentsMargins(2, 2, 2, 2);
	setLayout(layout);

	m_scaleComboBox->setEditable(true);
	m_scaleComboBox->setValidator(new QIntValidator(this));
	for (const auto& iter : SCALE_COMBOBOX_ITEMS)
		m_scaleComboBox->addItem(iter);
	m_scaleComboBox->setCurrentText(QString("100"));

	connect(m_scaleComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this,
		&SvgBottomToolBar::_ChangeScale);

	layout->addWidget(palette);
	layout->addSpacerItem(new QSpacerItem(0, 40, QSizePolicy::Expanding));
	layout->addWidget(m_scaleComboBox);
}

void SvgBottomToolBar::ChangeScale(double scale) const
{
	m_scaleComboBox->setCurrentText(QString::number(static_cast<int>(scale * 100)));
}

void SvgBottomToolBar::_ChangeScale(const int idx)
{
	emit ScaleChanged((m_scaleComboBox->itemText(idx).toDouble() / 100));
}
